package main

import (
	"encoding/json"
	"fmt"
)

func main() {
	//mapToJson()
	stringToMap()
}

/**
  map转换成json
*/
func mapToJson() {
	//var mapData (map[string]string)
	//mapData = make(map[string]string)
	var mapData = make(map[string]string)
	mapData["id"] = "11"
	mapData["name"] = "22"
	data, err := json.Marshal(mapData)
	if err != nil {
		fmt.Println(err)
	}
	fmt.Println(string(data))
}

/**
  字符串转成map
*/
func stringToMap() {
	var data = `{"id":"111","name":"test11"}`
	var mapData map[string]string
	mapData = make(map[string]string)
	json.Unmarshal([]byte(data), &mapData)
	fmt.Println(mapData)
}
